unit Unit4;

interface

uses SysUtils, Forms, Dialogs, Classes, Controls, StdCtrls, header;

type
  TForm4 = class(TForm)
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit5: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label7: TLabel;
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button4Click(Sender: TObject);
  private
    //FileTag: TID3v2;
    //procedure ClearAll;
  end;

var
  Form4: TForm4;

implementation

uses Unit1;

{$R *.dfm}
{
procedure TForm4.ClearAll;
begin
  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';
  ComboBox2.ItemIndex := 0;
  Edit5.Text := '';
  ComboBox1.ItemIndex := 0;
end;
}
procedure TForm4.FormCreate(Sender: TObject);
begin
  //FileTag := TID3v2.Create;
end;

procedure TForm4.ListBox1Click(Sender: TObject);
begin
{  if (ExtractFileExt(Form1.plist[ListBox1.ItemIndex]) = '.mp3') or
     (ExtractFileExt(Form1.plist[ListBox1.ItemIndex]) = '.MP3')
  then
  begin
  ClearAll;                                                   // Clear captions 
  if FileExists(Form1.plist[ListBox1.ItemIndex])
  then                                                         // Load tag data
  if FileTag.ReadFromFile(Form1.plist[ListBox1.ItemIndex])
  then
  if FileTag.Exists
  then
  begin                                                        // Fill captions
    Edit1.Text := FileTag.Title;
    Edit2.Text := FileTag.Artist;
    Edit3.Text := FileTag.Album;
    if (ComboBox2.Items.IndexOf(FileTag.Year) = -1) and
       (FileTag.Year <> '')
    then
    begin
      ComboBox2.Items.Add(FileTag.Year);
      ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(FileTag.Year);
    end
    else ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(FileTag.Year);
    Edit5.Text := FileTag.Comment;
    if (ComboBox1.Items.IndexOf(FileTag.Genre) = -1) and
       (FileTag.Genre <> '')
    then
    begin
      ComboBox1.Items.Add(FileTag.Genre);
      ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(FileTag.Genre);
    end
    else ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(FileTag.Genre);
  end
  else ShowMessage('Can not read tag from the file: ' + Form1.plist[ListBox1.ItemIndex])
  else ShowMessage('The file does not exist: ' + Form1.plist[ListBox1.ItemIndex])
  end
  else ShowMessage('Wrong file type (not mp3)');   }
end;

procedure TForm4.FormShow(Sender: TObject);
//var i: integer;
begin
//  for i := 0 to Form1.plist.Count - 1 do ListBox1.Items.Add(Form1.plist[i]);
//  ClearAll;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin                                                       // Prepare tag data
{  FileTag.Title := Edit1.Text;
  FileTag.Artist := Edit2.Text;
  FileTag.Album := Edit3.Text;
  FileTag.Year := ComboBox2.Items.Strings[ComboBox2.ItemIndex];
  FileTag.Comment := Edit5.Text;
  FileTag.Genre := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
  if (not FileExists(Form1.plist[ListBox1.ItemIndex]))      // Save tag data
 or (not FileTag.SaveToFile(Form1.plist[ListBox1.ItemIndex]))
  then ShowMessage('Can not save tag to the file: ' + Form1.plist[ListBox1.ItemIndex]); }
end;

procedure TForm4.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TForm4.Button3Click(Sender: TObject);
begin
  Form1.PlaySong(ptnext);
end;

procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction);
begin
//  Form1.ListBox1.Clear;
//  Form1.LoadList;
end;

procedure TForm4.Button4Click(Sender: TObject);
begin
//  Form1.ListBox1.Clear;
//  Form1.LoadList;
end;

end.
